/**
 * @Author: lclangcheng
 * @Date:   2018-08-06 10:14:28
 * @Email:  lclangcheng@gmail.com
 * @Filename: mysql_pools.js
 * @Last modified by:   lclangcheng
 * @Last modified time: 2018-08-06 10:16:20
 * @License: jin10
 * @Copyright: jin10
 */
'use strict'

const config = require('config')
const MySQL = require('mysql2')

const mysqlPools = {}

class MysqlPool {
  constructor (connect = 'default') {
    if (mysqlPools[connect] === undefined) {
      mysqlPools[connect] = MySQL.createPool({
        host: config.mysql[connect].host,
        user: config.mysql[connect].user,
        password: config.mysql[connect].pass,
        database: config.mysql[connect].db,
        connectionLimit: config.mysql[connect].poll_size,
        port: config.mysql[connect].port
      })
    }
    return mysqlPools[connect]
  }
}

module.exports = MysqlPool
